//
//  BaoXianInfoViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/3.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "BaoXianInfoViewController.h"
#import "JTCSM.h"
#import "BaoxininfoView.h"
#import "BaoxinInfoModel.h"
#import "WebViewController.h"
static CGFloat viewHeight = 80;
static CGFloat space = 20;
static CGFloat lineHeight = 25;

@interface BaoXianInfoViewController ()
{
    UIScrollView *backScrollV;
    
    UILabel *infoLabel;
    UILabel *moreLabel;
    BaoxinInfoModel *mymodel;

}
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *numberLabel;
@property (nonatomic,strong) UILabel *contentLabel;
@property (nonatomic,strong) UIImageView *statusImageView;
@end

@implementation BaoXianInfoViewController
- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    backScrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight)];
    backScrollV.backgroundColor = [UIColor whiteColor];
    backScrollV.userInteractionEnabled = YES;
    backScrollV.bounces = NO;
    backScrollV.showsVerticalScrollIndicator = NO;
    [self.view addSubview:backScrollV];
    [self layoutHeaderView];
    [self layoutInfoLabel];
//    [self layoutBottomView];
    [self loadMoreDataRequest];
    // Do any additional setup after loading the view.
}

- (void)layoutHeaderView{
    
    
    CGFloat top = 10;
    [df lineViewWithHeightofTop:top superView:backScrollV spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:top];
    self.statusImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KCONTROLLERWith-viewHeight-space, top*2, viewHeight, viewHeight)];
    [self.statusImageView setImage:[UIImage imageNamed:@"bg_04.png"]];
    [self.statusImageView setHighlightedImage:[UIImage imageNamed:@"bg_06.png"]];
    [backScrollV addSubview:self.statusImageView];
    
    self.nameLabel = [UILabel initWithFrame:CGRectMake(space, top*2, self.statusImageView.frame.origin.x-space, viewHeight/3) text:@"王者管家账户安全险" font:20 textAlignment:NSTextAlignmentLeft texcolor:[UIColor blackColor] backgroundColor:nil];
    [backScrollV addSubview:self.nameLabel];
    
    self.numberLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(self.nameLabel), self.statusImageView.frame.origin.x-space, viewHeight/3) text:@"NO.163483498934903473498" font:16 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(133, 133, 133, 1) backgroundColor:nil];
    [backScrollV addSubview:self.numberLabel];

    self.contentLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(self.numberLabel), self.statusImageView.frame.origin.x-space, viewHeight/3) text:@"由人保财险承保" font:14 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(133, 133, 133, 1) backgroundColor:nil];
    [backScrollV addSubview:self.contentLabel];
    
    [df lineViewWithHeightofTop:KVIEW_Y(self.contentLabel)+14 superView:backScrollV spacing:space color:RGBACOLOR(225, 43, 39, 1) lineHeight:4];

}

- (void)layoutInfoLabel{
    
    NSArray *dataarray = @[@"保障对象   ",@"被保险人   ",@"保障开始时间   ",@"保障结束时间   ",@"服务热线   "];
    CGFloat infoLabelHeight = 35;
    for (int i = 0; i<dataarray.count; i++) {
        
        UILabel *label = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(self.contentLabel)+space+14+infoLabelHeight*i, KCONTROLLERWith-2*space, infoLabelHeight) text:dataarray[i] font:16 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        [backScrollV addSubview:label];
        infoLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(self.contentLabel)+space+14+infoLabelHeight*i, KCONTROLLERWith-2*space, infoLabelHeight) text:dataarray[i] font:16 textAlignment:NSTextAlignmentRight texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        infoLabel.tag = 10000+i;
//        [df fuwenbenLabel:infoLabel FontNumber:[UIFont systemFontOfSize:16] AndRange:NSMakeRange(0, 4) AndColor:RGBACOLOR(133, 133, 133, 1)];
        [backScrollV addSubview:infoLabel];
    }
    
//    UILabel *tiaoyueLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(infoLabel), KCONTROLLERWith-2*space, infoLabelHeight) text:@"查看 《保险条约》" font:16 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(227, 68, 40, 1) backgroundColor:nil];
//    [df fuwenbenLabel:tiaoyueLabel FontNumber:[UIFont systemFontOfSize:16] AndRange:NSMakeRange(0, 2) AndColor:RGBACOLOR(133, 133, 133, 1)];
//    [backScrollV addSubview:tiaoyueLabel];
//    [df lineViewWithHeightofTop:KVIEW_Y(tiaoyueLabel)+space+lineHeight superView:backScrollV spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:lineHeight];
//    tiaoyueLabel.userInteractionEnabled = YES;
//    [df addTapGestureRecognizerWithTarget:self action:@selector(getTiaoYue) andaddView:tiaoyueLabel];
//
//    moreLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(tiaoyueLabel)+space+lineHeight, KCONTROLLERWith-2*space, 40) text:@"查看更多资金保障" font:16 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(227, 68, 40, 1) backgroundColor:nil];
//    [backScrollV addSubview:moreLabel];
//    moreLabel.userInteractionEnabled = YES;
//    [df addTapGestureRecognizerWithTarget:self action:@selector(getMoreBaozhang) andaddView:moreLabel];
    
//    [df lineViewWithHeightofTop:KVIEW_Y(moreLabel)+lineHeight superView:backScrollV spacing:0 color:RGBACOLOR(241, 241, 241, 1) lineHeight:lineHeight];

}

#pragma mark  查看条约
- (void)getTiaoYue{
   
}

#pragma mark 更多资金保障

- (void)getMoreBaozhang{
    WebViewController *vc = [[WebViewController alloc]init];
    vc.titleName =@"更多资金保障";
    vc.urlStr = mymodel.more_link;
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)layoutBottomView{
    CGFloat viewHeight = 40;
    NSArray *array = @[@"到期自动续签服务",@"理赔流程",@"常见问题"];
    BaoxininfoView *view;
    for (int i = 0; i<array.count; i++) {
        view = [[BaoxininfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(moreLabel)+lineHeight+viewHeight*i, KCONTROLLERWith, viewHeight) title:array[i] content:(i == 0)?@"已关闭":@"" imagename:@"jiantouxia.png"];
        [backScrollV addSubview:view];
    }
    
    [backScrollV setContentSize:CGSizeMake(KCONTROLLERWith, KVIEW_Y(view)+space)];
}

- (void)loadMoreDataRequest{
    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"UserPolicy/detail") withDict:@{@"token":KTokenString,@"policy_id":self.policy_id} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            NSDictionary *dict = KResultOfKey(@"data");
            mymodel = [BaoxinInfoModel whc_ModelWithJson:dict];
            
            [self setvalue];
        }
    }];
    
}

- (void)setvalue{
    
    NSArray *data = @[mymodel.company,mymodel.truename,mymodel.use_start,mymodel.use_end,mymodel.customer];
    for (int i = 0; i<data.count; i++) {
        UILabel *label = [backScrollV viewWithTag:i+10000];
        label.text = data[i];
    }
    
    if ([mymodel.status integerValue] == 1) {
        self.statusImageView.highlighted = NO;
    }else{
        self.statusImageView.highlighted = YES;
    }
    
    self.nameLabel.text = mymodel.title;
    self.numberLabel.text = mymodel.client_num;
    self.contentLabel.text = mymodel.company;

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
